package com.nbjtjc.safe.api.report;

import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduRequirementInvestigationMapper;
import com.nbjtjc.safe.model.edu.EduRequirementInvestigation;
import com.nbjtjc.safe.service.report.EduReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @auther guqianbin
 * @date 2018/5/8 11:01
 **/
@RestController
@RequestMapping("/report/edu")
@CrossOrigin("*")
public class EduReportController {

    @Autowired
    private EduReportService eduReportService;
    @Autowired
    private EduRequirementInvestigationMapper eduRequirementInvestigationMapper;

//查询有台账的年份
    @RequestMapping(value = "/findYear",method = {RequestMethod.POST})
    public Result findYear(){
    	
        return eduReportService.findYear();
    }
//按年份查询该年份有哪些台账
    @SysLog("按年份查询年度台账")
    @GetMapping(value = "/eduList/{year}")
    public Result eduList(HttpServletResponse response,@PathVariable("year")  String year){
        Result result=new Result();

    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Date yeard;
		try {
			yeard = sdf.parse(year);
	        result = eduReportService.eduList(response,yeard);

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return result;
    }
    
    
    /**
     *导出从业人员的花名册
     *done
     * @param response
     * @param sysUser
     */
    @SysLog("下载从业人员的花名册")
    @GetMapping(value = "/eduUserListExcel/{year}")
    public void eduUserListExcel(HttpServletResponse response,@PathVariable("year")  String year){
        eduReportService.eduUserListExcel(response,year);
    }
    
    /**
     * 导出安全培训教育需求调查表
     *done
     * @param response
     * @param eduRequirementInvestigationId
     */
//    @SysLog("下载安全培训教育需求调查表")
//    @GetMapping(value = "/eduRequirementInvestExcel/{year}")//旧一年个需求调查
//    public Result eduRequirementInvestExcel(HttpServletResponse response,@PathVariable("year")  String year){
//        Result result=new Result();
//
//    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
//		Date yeard;
//		try {
//			yeard = sdf.parse(year);
//			result = eduReportService.eduRequirementInvestExcel(response,yeard);
//
//		} catch (ParseException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//    	return result;
//    }
    
//    @SysLog("下载安全培训教育需求调查表")
//    @GetMapping(value = "/eduRequirementInvestExcel/{year}")//一年多个需求调查
//    public Result eduRequirementInvestExcel(HttpServletResponse response,@PathVariable("year")  String year){
//        Result result=new Result();
//
//    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
//		Date yeard;
//		List<Integer> reqIds =new ArrayList();
//		try {
//			yeard = sdf.parse(year);
//			
//        	//根据年份找出需求调查主表ID
//        	EduRequirementInvestigation eduRequirementInvestigationSample = new EduRequirementInvestigation();
//        	eduRequirementInvestigationSample.setCreateYear(yeard);
//        	eduRequirementInvestigationSample.setCompanyId(MyShiroUtils.getCompanyId());
//
//        	List<EduRequirementInvestigation> eduRequirementInvestigations = eduRequirementInvestigationMapper.search(eduRequirementInvestigationSample);
//        	if(CollectionUtil.isEmpty(eduRequirementInvestigations)){
////        		result.setFalse("该年份需求调查记录为空");
//        		return result;
//        	}else{
//        		for(int i=0;i<eduRequirementInvestigations.size();i++){
//        			if(ObjectUtil.isNotNull(eduRequirementInvestigations.get(i))&&ObjectUtil.isNotNull(eduRequirementInvestigations.get(0).getId())){
//        				reqIds.add(eduRequirementInvestigations.get(0).getId());
//        			}
//        		}
//        	}
//        	
//        	if(CollectionUtil.isNotEmpty(reqIds)){
//        		for(int i=0;i<reqIds.size();i++){
//        			result = eduReportService.eduRequirementInvestExcel(response,reqIds.get(i),i+1);
//        			if(result.isSuccess()==false){
//        				return result;
//        			}
//        		}
//        	}
//        	
//			return result;
//		} catch (ParseException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//    	return result;
//    }
    
    @SysLog("下载安全培训教育需求调查表")
    @GetMapping(value = "/eduRequirementInvestExcel/{reqId}")
    public Result eduRequirementInvestExcel(HttpServletResponse response,@PathVariable("reqId")  Integer reqId){
        Result result=new Result();

		try {
			result = eduReportService.eduRequirementInvestExcel(response,reqId);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return result;
    }
    @SysLog("下载安全培训教育需求调查表")
    @RequestMapping(value = "/eduRequirementInvestExcel",method = {RequestMethod.POST})
    public void eduRequirementInvestExcel(HttpServletResponse response,@RequestBody EduRequirementInvestigation eduRequirementInvest){
			eduReportService.eduRequirementInvestExcel(response,eduRequirementInvest.getId());
    }
    
    /**
     * 导出安全培训教育计划表
     *done
     * @param response
     * @param eduPlanId,year
     */
    @SysLog("下载安全培训教育计划表")
    @GetMapping(value = "/eduPlanExcel/{year}")
    public Result eduPlanExcel(HttpServletResponse response,@PathVariable("year") String year){
    	
        Result result=new Result();

    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Date yeard;
		try {
			yeard = sdf.parse(year);
	        eduReportService.eduPlanExcel(response,yeard);

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return result;
    }
    
    /**
     * 导出安全生产相关负责人及安全生产管理人员安全培训教育登记表
     *done
     * @param response
     */
    @SysLog("下载安全生产相关负责人及安全生产管理人员安全培训教育登记表")
    @GetMapping(value = "/eduCertificateExcel/{year}")
    public Result eduCertificateExcel(HttpServletResponse response,@PathVariable("year") String year){
    	Result result = new Result();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Date yeard;
		try {
			yeard = sdf.parse(year);
//			System.out.println("开始时间"+yeard);
			result = eduReportService.eduCertificateExcel(response,yeard);

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
    }
    
    /**
     * 导出新入职人员安全培训教育登记表
     *
     * @param response
     */
    @SysLog("下载新入职人员安全培训教育登记表")
    @GetMapping(value = "/eduTrainExcel/{year}")
    public Result eduTrainExcel(HttpServletResponse response,@PathVariable("year") String year){
    	Result result = new Result();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Date yeard;
		try {
			yeard = sdf.parse(year);
	    	eduReportService.eduTrainExcel(response,yeard);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
    }

    /**
     * 导出转岗、调岗、脱岗人员安全培训教育登记表
     *done
     * @param response
     */
    @SysLog("下载转岗、调岗、脱岗人员安全培训教育登记表")
    @GetMapping(value = "/eduReassignmentExcel/{year}")
    public Result eduReassignmentExcel(HttpServletResponse response,@PathVariable("year") String year){
    	Result result = new Result();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Date yeard;
		try {
			yeard = sdf.parse(year);
//			System.out.println("开始时间"+yeard);
	        eduReportService.eduReassignmentExcel(response,yeard);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
    }
    
    /**
     * 导出从业人员日常安全培训教育登记表
     *done
     * @param response
     * @param year
     */
    @SysLog("下载从业人员日常安全培训教育登记表")
    @GetMapping(value = "/eduDailyInfoExcel/{year}")
    public void eduDailyInfoExcel(HttpServletResponse response,@PathVariable("year") String year){
        eduReportService.eduDailyInfoExcel(response,year);
    }
    
    /**
     * 导出教育培训活动记录
     *
     * @param response
     * @param eduDailyRecordId
     */
    @SysLog("下载教育培训活动记录")
    @RequestMapping(value = "/eduDailyRecordExcel",method = {RequestMethod.POST})
    public void eduDailyRecordExcel(HttpServletResponse response, int eduDailyRecordId){
        eduReportService.eduDailyRecordExcel(response,eduDailyRecordId);
    }
    
    /**
     * 导出教育培训日常培训考核表
     *
     * @param response
     * @param eduDailyExamineListId
     */
    @SysLog("下载教育培训日常培训考核表")
    @RequestMapping(value = "/eduDailyExamineListExcel",method = {RequestMethod.POST})
    public void eduDailyExamineListExcel(HttpServletResponse response, int eduDailyExamineListId){
        eduReportService.eduDailyExamineListExcel(response,eduDailyExamineListId);
    }

}
